import ajax from '../untils/request.js'

// 获取文章评论信息
export const getComment = (articleID, offset) => {
  return ajax({
    url: '/app/v1_0/comments',
    method: 'GET',
    params: {
      type: 'a',
      source: articleID,
      offset
    }
  })
}

// 添加评论
export const addComment = (articleID, content) => {
  return ajax({
    url: '/app/v1_0/comments',
    method: 'POST',
    data: {
      target: articleID,
      content
    }
  })
}

// 评论点赞
export const likeComment = (commentID) => {
  return ajax({
    url: '/app/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: commentID
    }
  })
}

// 取消对评论点赞
export const canclelikeComment = (commentID) => {
  return ajax({
    url: '/app/v1_0/comment/likings/' + commentID,
    method: 'DELETE'
  })
}

// 获取回复评论
/**
 *
 * @param {*} commentID //评论ID
 * @param {*} offset  //下次请求的截止ID
 */
export const getCommentReply = (commentID, offset) => {
  return ajax({
    url: '/app/v1_0/comments',
    method: 'GET',
    params: {
      type: 'c',
      source: commentID,
      offset
    }
  })
}

// 添加评论回复
/**
 *
 * @param {*} commentID //评论ID
 * @param {*} content  // 回复内容
 */
export const addCommentReply = (commentID, articleID, content) => {
  return ajax({
    url: '/app/v1_0/comments',
    method: 'POST',
    data: {
      target: commentID,
      art_id: articleID,
      content
    }
  })
}
